package utility.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author lit
 * @date 2018/3/20.
 */
public class DatabaseAccess {
    /**
     * 获取数据库连接
     * @param driverName
     * @param url
     * @param user
     * @param passwd
     * @return
     * @throws ClassNotFoundException
     * @throws SQLException
     */
    public static Connection getConnection(String driverName, String url, String user, String passwd) throws ClassNotFoundException, SQLException {
        Class.forName(driverName);
        Connection connection = null;
        connection = DriverManager.getConnection(url, user, passwd);
        if( connection != null && !connection.isClosed() ){
            connection.setAutoCommit(true);
        }
        return connection;
    }
}
